Add user.prompt_submit and stop project hooks to code-rs#581
Open
voarsh2 wants to merge 1 commit intojust-every:mainfrom
Open
Add user.prompt_submit and stop project hooks to code-rs#581voarsh2 wants to merge 1 commit intojust-every:mainfrom
voarsh2 wants to merge 1 commit intojust-every:mainfrom
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 94f6820a7e
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Extend code-rs project hooks with two new lifecycle events: - user.prompt_submit - stop This adds minimal upstream-inspired hook semantics for: - blocking a user prompt via exit code 2 + stderr - injecting prompt context into model input via stdout - continuing a turn from a stop hook via stderr - preventing recursive stop-hook continuation loops Also enrich hook payloads with session/turn metadata needed by adapter-backed integrations: - session_id - turn_id - transcript_path - model Includes focused regression coverage for fire/block/injection/stop/ loop-guard behavior, plus a debug-build TUI fix for background-event prelude insertion.
94f6820 to
a3ac5f5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR extends
code-rsproject hooks with two new lifecycle events:user.prompt_submitstopThe goal is to bring
code-rscloser to upstream Codex hook behavior forprompt-time context injection and end-of-turn continuation, while staying
inside the existing project-hook architecture.
What changed
New project hook events
Added support for:
user.prompt_submitstopFor compatibility with upstream naming,
UserPromptSubmitandStopareaccepted as config aliases.
Prompt-submit semantics
user.prompt_submitnow supports minimal upstream-inspired behavior:0: continue normally2with non-empty stderr: block the promptThis enables integrations that need to add context at prompt time.
Stop semantics
stopnow supports end-of-turn continuation:0: allow the turn to finish normally2with non-empty stderr: treat stderr as a continuation promptHook payload enrichment
To support integrations that need richer lifecycle metadata, hook payloads now include:
session_idturn_idwhere applicabletranscript_pathmodelThis applies to
session.start,user.prompt_submit, andstop.TUI fix
Also fixes a debug-build TUI assertion where a background event inserted during
prelude/startup could be tagged incorrectly and panic.
Validation
Focused tests
Passed:
cargo test -p code-core --test tool_hooks -- --nocapturecargo test -p code-core project_hook_event_deserializes_upstream_aliases -- --nocaptureCoverage includes:
Build
Passed:
cargo build --bin code --bin code-tui --bin code-execSmoke validation
A built-binary smoke harness was used during development to verify:
user.prompt_submitfiresstopfiresNon-goals
This PR does not add:
This stays within the existing project-hook framework.